<template>
  <!-- <div class="header">
   
  </div> -->
  <div class="bg-img-box">
    <div class="bg-img"></div>
  </div>
  <div class="box">
    <router-link to="StoreMain">
      <div class="logo"></div>
    </router-link>

    <div class="input-box">
      <label>账号</label>
      <input type="text" v-model="username" />
    </div>
    <div class="input-box">
      <label>密码</label>
      <input type="password" v-model="password" />
    </div>
    <div class="input-box">
      <label>确认密码</label>
      <input type="password" v-model="repassword" />
    </div>
    <div class="btn-box">
      <div>
        <button @click="toRegister">注册</button>
      </div>
      <div class="span_footer">
        <router-link to="login">已有账号，立即登录!</router-link>
      </div>
    </div>
  </div>
</template>

<script>
import { useRouter } from "vue-router";
//生成不重复的id
import { v1 as uuidv1 } from "uuid";
import { ref } from "vue";
import { register } from "@/api/api.js";
export default {
  name: "register",
  setup() {
    const username = ref("");
    const password = ref("");
    const repassword = ref("");
    const router = useRouter();
    // console.log(uuidv1());
    const toRegister = () => {
      if (password.value == repassword.value) {
        let data = {
          id: uuidv1(),
          username: username.value,
          password: password.value,
          img: "https://cube.elemecdn.com/3/7c/3ea6beec64369c2642b92c6726f1epng.png",
        };
        register("post", data).then(() => {
          alert("注册成功！");
          // setTimeout(()=>{
              router.push("/login");
          // },200)
        });
      }else{
        alert("两次输入密码不匹配")
      }
    };
    return {
      username,
      password,
      repassword,
      toRegister,
    };
  },
};
</script>

<style lang="scss" scoped>
// 模糊背景
.bg-img-box {
  display: flex;
  flex-direction: column;
  position: absolute;
  bottom: 0;
  top: 0;
  left: 0;
  right: 0;
  overflow: hidden;
}
.bg-img {
  width: 100%;
  height: 100%;
  background: url(@/assets/background.jpg);
  background-repeat: no-repeat;
  background-size: cover;
  filter: blur(20px);
  transform: scale(1.5);
  background-position: 50%;
}
.bg-img::after {
  content: " ";
  display: block;
  width: 100%;
  height: 400rpx;
  background: rgba(17, 17, 17, 0.2);
  z-index: 1;
}
// 登录
.box {
  width: 750px;
  height: 500px;
  margin: 0 auto;
  margin-top: 120px;
  border-top: 1px solid rgba(255, 255, 255, 0.5);
  border-left: 1px solid rgba(255, 255, 255, 0.5);
  border-bottom: 1px solid rgba(255, 255, 255, 0.3);
  border-right: 1px solid rgba(255, 255, 255, 0.3);
  backdrop-filter: blur(10px);
  background: rgba(50, 50, 50, 0.2);
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  border-radius: 10px;
}

.box > h2 {
  color: rgba(255, 255, 255, 0.9);
  margin-bottom: 30px;
}

.box .input-box {
  display: flex;
  flex-direction: column;
  box-sizing: border-box;
  margin-bottom: 10px;
}

.box .input-box label {
  font-size: 13px;
  color: rgba(255, 255, 255, 0.9);
  margin-bottom: 5px;
}

.box .input-box input {
  letter-spacing: 1px;
  font-size: 14px;
  box-sizing: border-box;
  width: 250px;
  height: 35px;
  border-radius: 5px;
  border: 1px solid rgba(255, 255, 255, 0.5);
  background: rgba(255, 255, 255, 0.2);
  outline: none;
  padding: 0 12px;
  color: rgba(255, 255, 255, 0.9);
  transition: 0.2s;
}

.box .input-box input:focus {
  border: 1px solid rgba(255, 255, 255, 0.8);
}

.box .btn-box {
  width: 250px;
  display: flex;
  flex-direction: column;
  align-items: start;
}

.span_footer > a {
  font-size: 13px;
  color: rgba(255, 255, 255, 0.7);
}

.span_footer > a:hover {
  color: rgba(255, 255, 255, 1);
}

.box .btn-box > div {
  margin-top: 10px;
  display: flex;
  justify-content: center;
  align-items: center;
  width: 100%;
}

.box .btn-box > div > button {
  outline: none;
  margin-top: 10px;
  display: block;
  font-size: 14px;
  border-radius: 5px;
  transition: 0.2s;
}

.box .btn-box > div > button:nth-of-type(1) {
  width: 120px;
  height: 35px;
  color: rgba(255, 255, 255, 0.9);
  border: 1px solid rgba(192, 119, 91, 0.7);
  background: rgba(156, 39, 176, 0.6);
  width: 70%;
}

.box .btn-box > div > button:hover {
  border: 1px solid rgba(251, 128, 71, 0.7);
  background: rgba(156, 39, 176, 1);
}
.span_footer {
  justify-content: start !important;
}
// logo
.logo {
  background: url(@/assets/logo_lr.png);
  height: 100px;
  width: 150px;
  background-position: center center;
  background-repeat: no-repeat;
  background-size: cover;
  margin-bottom: 30px;
}
</style>